/*
 * Copyright (c) [2019] Zhang Yansen.All rights reserved.
 *
 * t-console is licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */


/**
 * 解析参数
 * 支持两种格式
 *  1. 参数一个 Object { label, value, type }, lable 必选
 *  2. 参数为多个, 顺序依次为 label, value, type  , lable 必选
 * @param  {...any} args 
 */
export function parse(...args) {
  if (!args.length) return;
  
  const first = args[0]
  if (typeof first === 'object') {
    const { label, value, type } = first
    if (!label) {
      return ;
    }

    return { label, value, type }
  }   

  if (typeof first === 'string') {
    const [ label, value, type ] = args
    if (!label) {
      return ;
    }

    return { label, value, type }
  }

  return '';
}
